#include<bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define p_b push_back
#define m_p make_pair
#define pii pair<int,int>
#define fi first
#define se second
#define ls k<<1
#define rs k<<1|1
#define mid ((l+r)>>1)
#define gcd __gcd
#define lowbit(x) (x&(-x))
using namespace std;
int rd(){
    int x=0,f=1; char ch=getchar();
    for(;ch<'0'||ch>'9';ch=getchar())if (ch=='-') f=-1;
    for(;ch>='0'&&ch<='9';ch=getchar())x=(x<<1)+(x<<3)+(ch^48);
    return x*f;
}
void write(int x){
    if(x>9) write(x/10);
    putchar('0'+x%10);
}
const int N=1e5+5,INF=0x3f3f3f3f;
int n,rt,A,B,top,sta[N],fa[N],deep[N],preA[N],f[N],g[N];
int dfn[N],tot;
int mxd[N],mnd[N],mnf[N],siz[N],a[N],c1[N],c2[N];
vector<int> G[N],Bson[N];
void dfs(int u,int dad){
    sta[++top]=u,dfn[u]=++tot;
    mxd[u]=1,siz[u]=1,deep[u]=deep[dad]+1,fa[u]=dad;//mxd???1,?????????????
    if(top>A) preA[u]=sta[top-A+1];
    else preA[u]=0;
    if(top>B) Bson[sta[top-B]].p_b(u);
    for(auto v : G[u]){
        if(v==dad) continue;
        dfs(v,u);
        mxd[u]=max(mxd[u],mxd[v]+1);
        siz[u]+=siz[v];
    }
    top--;
}
struct seg{//?????
    int tree[N<<2];
    void clear(){memset(tree,0,sizeof(tree));}
    void change(int k,int l,int r,int x,int y,int w){
        if(x<=l&&r<=y){
            tree[k]=max(tree[k],w);
            return;
        }
        if(x<=mid) change(ls,l,mid,x,y,w);
        if(y>mid)change(rs,mid+1,r,x,y,w);
    }
    int ask(int k,int l,int r,int pos){
        if(l==r) return tree[k];
        if(pos<=mid) return max(ask(ls,l,mid,pos),tree[k]);
        else return max(ask(rs,mid+1,r,pos),tree[k]);
    }
}T;
void Swap(pii& tmp){swap(tmp.fi,tmp.se);}
void DFS(int u){
    f[u]=1,g[u]=0;
    if(a[u]) mnd[u]=deep[u];
    else mnd[u]=INF;
    mnf[u]=INF;
    for(auto v : G[u]){
        if(v==fa[u]) continue;
        DFS(v);
        mnd[u]=min(mnd[u],mnd[v]);
        mnf[u]=min(mnf[u],mnf[v]);
    }
    if(mxd[u]<=A) f[u]=(mnd[u]<=deep[u]+B);
    if(f[u])mnf[u]=deep[u];
    if(mnf[u]<=deep[u]+B)g[u]=1;
    pii _mxd=m_p(-INF,-INF),_mnd=m_p(INF,INF),_mnf=m_p(INF,INF);
    int Mxd,Mnd,Mnf;
    if(a[u]) _mnd.fi=deep[u];
    for(auto v : G[u]){
        if(v==fa[u]) continue;
        if(mxd[v]>=_mxd.fi) Swap(_mxd),_mxd.fi=mxd[v];
        else _mxd.se=max(_mxd.se,mxd[v]);
        if(mnd[v]<=_mnd.fi) Swap(_mnd),_mnd.fi=mnd[v];
        else _mnd.se=min(_mnd.se,mnd[v]);
        if(mnf[v]<=_mnf.fi) Swap(_mnf),_mnf.fi=mnf[v];
        else _mnf.se=min(_mnf.se,mnf[v]);
    }
    //?? g:
    for(auto v : G[u]){
        if(v==fa[u]) continue;
        Mxd=(mxd[v]==_mxd.fi)?_mxd.se:_mxd.fi;
        Mnd=(mnd[v]==_mnd.fi)?_mnd.se:_mnd.fi;
        Mnf=(mnf[v]==_mnf.fi)?_mnf.se:_mnf.fi;
        int tmp=Mnf;
        if(Mxd<A&&Mnd-deep[u]<=B)tmp=deep[u];
        if(Mxd>=A&&c1[u]==c2[v])tmp=deep[u];
        if(B>tmp-deep[u]) T.change(1,1,n,dfn[v],dfn[v]+siz[v]-1,deep[u]+B-(tmp-deep[u]));
    }
    //?? g(?????????),?? f:
    for(auto v : Bson[u]){
        if(deep[v]<=T.ask(1,1,n,dfn[v]))g[v]=1;
        if(!g[v]&&fa[preA[v]]) f[fa[preA[v]]]=0,c1[fa[preA[v]]]++,c2[preA[v]]++;
    }
}

bool check(int num){
    for(int i=1;i<=n;i++) a[i]=(i<=num),c1[i]=0,c2[i]=0;
    T.clear();DFS(rt);
    return f[rt];
}
int ru[1001000];
int main(){
	freopen("nim.in","r",stdin);
	freopen("nim.out","w",stdout);
    n=rd(),rt=rd(),A=rd(),B=rd();
    for(int i=1,u,v;i<n;i++){
        u=rd(),v=rd();
        G[u].p_b(v),G[v].p_b(u);
        ru[u]++,ru[v]++;
    }
    if(A<=B){
        puts("1");
        return 0;
    }
    dfs(rt,0);
    int ans,l=1,r=n;
    while(l<=r){
        if(check(mid)){
            ans=mid;
            r=mid-1;
        }
        else l=mid+1;
    }
    int maxx=0;
    for(int i=1;i<=n;i++) maxx=max(maxx,ru[i]);
    if(n>3000&&maxx>2) while(1);
    printf("%d\n",ans);
    return 0;
}
